import { Module } from '@nestjs/common';
import { DeviceDataProcessingService } from './device-data-processing.service';
import { MqttClientModule } from 'apps/mqtt-client/src/mqtt-client.module';
import { ConfigureModule, ConfigureService } from '@app/configure';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Device } from '@app/db/entities/Device';
import { CacheModule } from '@app/cache';
import { OrderPowerData, OrderPowerDataSchema } from '@app/mongodb/schemas/orderPowerData';
import { DeviceData, DeviceDataSchema } from '@app/mongodb/schemas/deviceData';
import { MongooseModule } from '@nestjs/mongoose';
import { PrivateChargePowerData, PrivateChargePowerDataSchema } from '@app/mongodb/schemas/privateChargePowerData';
import { OtaModule } from './ota/ota.module';

@Module({
  imports: [
    MqttClientModule,
    ConfigureModule,
    CacheModule,
    TypeOrmModule.forRootAsync({
      imports : [ConfigureModule],
      inject : [ConfigureService],
      useFactory : (config:ConfigureService) => {
        return {
          ...config.get('database.default'),
          poolSize : 2
        }
      }
    }),
    
    TypeOrmModule.forFeature([Device]),

    MongooseModule.forRootAsync({
      imports : [ConfigureModule],
      inject : [ConfigureService],
      useFactory : (config:ConfigureService) => {
        return {
          ...config.get('mongodb'),
        }
      }
    }),

    MongooseModule.forFeature([
      {name : DeviceData.name, schema : DeviceDataSchema},
      {name : OrderPowerData.name, schema : OrderPowerDataSchema},
      {name : PrivateChargePowerData.name, schema : PrivateChargePowerDataSchema},
    ]),

    OtaModule
  ],
  providers: [DeviceDataProcessingService],
})
export class DeviceDataProcessingModule {}
